package com.hontech.bv.ui.fragment.pipe_line

import android.view.View
import com.hontech.bv.R
import com.hontech.bv.model.pipe_line.PipeLineStatus
import com.hontech.bv.ui.view.NumberSensorView
import com.hontech.bv.ui.view.SwitchSensorView

class StatusDelegate (view: View) {

    private val nsvAdc = view.findViewById<NumberSensorView>(R.id.id_pl_nsv_adc)

    private val swMaxDoor = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_max_door)
    private val swMinDoor = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_min_door)
    private val swLockClose = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_lock_close)
    private val swDrop1 = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_drop1)
    private val swDrop2 = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_drop2)
    private val swStepOrigin = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_step_origin)
    private val swStationPearl = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_station_pearl)
    private val swStationPowder = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_station_powder)
    private val swStationArm = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_station_arm)
    private val swStationDrop1 = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_station_drop1)
    private val swStationDrop2 = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_station_drop2)
    private val swStationStepAlm = view.findViewById<SwitchSensorView>(R.id.id_pl_sw_step_alm)

    fun update() {
        val status = PipeLineStatus.status
        val sw = status.switchValue()

        nsvAdc.set(status.adc.value)

        swMaxDoor.set(sw.isMaxDoorClose)
        swMinDoor.set(sw.isMinDoorClose)
        swLockClose.set(sw.isLockClose)
        swDrop1.set(sw.isDrop1)
        swDrop2.set(sw.isDrop2)
        swStepOrigin.set(sw.isStepMotorOrigin)
        swStationPearl.set(sw.isStationPearl)
        swStationPowder.set(sw.isStationPowder)
        swStationArm.set(sw.isStationArm)
        swStationDrop1.set(sw.isStationDrop1)
        swStationDrop2.set(sw.isStationDrop2)
        swStationStepAlm.set(sw.isStepMotorAlm)
    }
}

